package presenter;

import base.BasePresenter;
import base.ResultCallBack;
import bean.CodeBean;
import bean.RegBean;
import model.RegModel;
import view.RegView;
import view.YingDaoView;

/**
 * Created by Windows on 2019/11/5.
 */

public class RegPresenter extends BasePresenter<RegView> {
    private RegModel model;

    public RegPresenter() {
        this.model=new RegModel();
        addModel(model);
    }

    //获取验证码
    public void requestCode(String phoneNum) {
        model.requestCode(phoneNum,"1", new ResultCallBack<CodeBean>() {
            @Override
            public void onSuccess(CodeBean codeBean) {
                if (mView!=null)
                    mView.onCodeSuccess(codeBean.getCode());

            }

            @Override
            public void onFail(String error) {
                if (mView!=null)
                   mView.showToast("获取验证码失败！请重试");

            }
        });


    }

    //注册
    public void reg(String phone, String password, int code) {
        model.reg(phone,password,code, new ResultCallBack<RegBean>() {
            @Override
            public void onSuccess(RegBean regBean) {
                if (mView!=null)
                    mView.onRegSuccess(regBean);
            }

            @Override
            public void onFail(String error) {
                if (mView!=null)
                    mView.showToast(error);

            }
        });
    }

}
